﻿using SRB.Tg.DrawingStandard;
using System;
using System.Collections.Generic;
using System.Linq;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class Plinth : MemberBase
    {
        private dParameter v1;
        private dParameter v2;
        private dParameter v3;
        PlinthParameter plinthParameter;
        public double Length, Width, Height;
        double out_dia, in_dia;

        List<double> ArrAlongW, ArrAlongL;
        Dictionary<int, int> dicNo = new Dictionary<int, int>();
        int netNumber = 1;
        public Plinth(PlinthParameter plinthPara)
        {
            plinthParameter = plinthPara;
            InitPileNo();
            double refH = 150;
            // 基本尺寸 (逻辑可能有问题,转厘米绘制)
          
            plinthPara.L = plinthPara.L ; 
            Length = plinthPara.L;
          
            plinthPara.W = plinthPara.W ;
   
            plinthPara.H = plinthPara.H ;
            refH= plinthPara.H ; 
            Width = plinthPara.W;
            Height = refH;
            CoverThk = plinthPara.Cover;


            #region 配筋            
            // 配筋     
            // 配筋外径12mm,内径10mm
            out_dia = 12;
            in_dia = 10;
            double L1 = 35 * in_dia - 0.5 * out_dia + plinthPara.H - CoverThk;

            GeneralRebar N1 = new GeneralRebar("N1", eRebarClass.R, eRebarDia.D10,
                            RebarEnd.NoneHook, RebarEnd.NoneHook);
            N1.LineSegmentList.Add(L1);
            N1.LineSegmentList.Add(Width - 2 * CoverThk - out_dia);
            N1.LineSegmentList.Add(L1);
            N1.BendList.Add(RebarBend.B90);
            N1.BendList.Add(RebarBend.B90);
            GeneralRebar N2 = new GeneralRebar("N2", eRebarClass.R, eRebarDia.D10,
                RebarEnd.NoneHook, RebarEnd.NoneHook);
            N2.LineSegmentList.Add(L1);
            N2.LineSegmentList.Add(Length - 2 * CoverThk - out_dia);
            N2.LineSegmentList.Add(L1);
            N2.BendList.Add(RebarBend.B90);
            N2.BendList.Add(RebarBend.B90);
            ArrAlongW = RebarArrangement.ArrangeT2BRebar(plinthPara.W - CoverThk * 2 - 2 * GeneralRebar.outerDia[plinthPara.N1] - GeneralRebar.outerDia[plinthPara.N3], 100);
            ArrAlongL = RebarArrangement.ArrangeT2BRebar(plinthPara.L - CoverThk * 2 - 2 * GeneralRebar.outerDia[plinthPara.N2] - GeneralRebar.outerDia[plinthPara.N4], 100);
            int numN1 = ArrAlongW.Count;
            int numN2 = ArrAlongL.Count;
            rebarList.Add(new Tuple<RebarBase, int>(N1, numN1));
            rebarList.Add(new Tuple<RebarBase, int>(N2, numN2));
            #endregion
        }


        /// <summary>
        /// 编号处理算法
        /// </summary>
        private void InitPileNo()
        {         
            dicNo = new Dictionary<int, int>();
            int no = 1;
            for (int i = 1; i < 5; i++)
            {
                dicNo.Add(i, i);
            }
            //是否合并 ？
            if (plinthParameter.W == plinthParameter.L && plinthParameter.N1 == plinthParameter.N2)
            {
                dicNo[2] = dicNo[1];
            }
            else
            {
                no++;
                dicNo[2] = no;
            }
            no++;
            dicNo[3] = no;
            if (plinthParameter.W == plinthParameter.L)
            {
                dicNo[4] = dicNo[3];
                netNumber = 1;
            }
            else
            {
                no++;
                dicNo[4] = no;
                netNumber = 2;
            }
        }
        /// <summary>

        /// <summary>
        /// 通过长宽和参考高度构造矩形垫石。
        /// </summary>
        /// <param name="L">顺桥向尺寸</param>
        /// <param name="W">横桥向尺寸</param>        
        /// <param name="refH">参考高度，默认150mm</param>
        /// <param name="cover">保护层厚度，默认50mm</param>
        public Plinth(double L, double W, double cover, double refH = 150)
        {
            // 基本尺寸
            Length = L;
            Width = W;
            Height = refH;
            CoverThk = cover;


            #region 配筋            
            // 配筋     
            // 配筋外径12mm,内径10mm
            out_dia = 12;
            in_dia = 10;
            double L1 = 35 * in_dia - 0.5 * out_dia + refH - CoverThk;           
            
            GeneralRebar N1 = new GeneralRebar("N1", eRebarClass.R, eRebarDia.D10,
                            RebarEnd.NoneHook, RebarEnd.NoneHook);
            N1.LineSegmentList.Add(L1);
            N1.LineSegmentList.Add(Width - 2 * CoverThk - out_dia);
            N1.LineSegmentList.Add(L1);
            N1.BendList.Add(RebarBend.B90);
            N1.BendList.Add(RebarBend.B90);
            GeneralRebar N2 = new GeneralRebar("N2", eRebarClass.R, eRebarDia.D10,
                RebarEnd.NoneHook, RebarEnd.NoneHook);
            N2.LineSegmentList.Add(L1);
            N2.LineSegmentList.Add(Length - 2 * CoverThk - out_dia);
            N2.LineSegmentList.Add(L1);
            N2.BendList.Add(RebarBend.B90);
            N2.BendList.Add(RebarBend.B90);
            //ArrAlongW = RebarArrangement.ArrangeRebar(W - CoverThk * 2 - 3 * out_dia, 100);
            //ArrAlongL = RebarArrangement.ArrangeRebar(L - CoverThk * 2 - 3 * out_dia, 100);
            ArrAlongW = RebarArrangement.ArrangeT2BRebar(W - CoverThk * 2 - 3 * out_dia, plinthParameter.sapceW);
            ArrAlongL = RebarArrangement.ArrangeT2BRebar(L - CoverThk * 2 - 3 * out_dia, plinthParameter.sapceL);
            int numN1 = ArrAlongW.Count;
            int numN2 = ArrAlongL.Count;
            rebarList.Add(new Tuple<RebarBase, int>(N1, numN1));
            rebarList.Add(new Tuple<RebarBase, int>(N2, numN2));
            #endregion




        }


        public void DrawingPlinth(Database db,int OverAllScale ,System.Data.DataTable dt1, System.Data.DataTable dt2)
        {
            Extents2d ExtPlan, ExtAA, ExtBB, ExtDetail;
            Point2d RefPtPlan, RefPtAA, RefPtBB, RefPtDetail;

            RefPtAA = Point2d.Origin;
            RefPtBB = RefPtAA.C2D(420 * OverAllScale*0.5);
            RefPtPlan = RefPtAA.C2D(0, -297 * OverAllScale * 0.5);
            RefPtDetail = RefPtPlan.C2D(420 * OverAllScale * 0.5);

            PlotPlan(ref db, out ExtPlan, RefPtPlan, OverAllScale);
            //BaseShapePloter.RenderEntity(db, ExtPlan.ConvertPL());

            PlotElevationA(ref db, out ExtAA, RefPtAA, OverAllScale);
            //BaseShapePloter.RenderEntity(db, ExtAA.ConvertPL());

            PlotElevationB(ref db, out ExtBB, RefPtBB, OverAllScale);
            //BaseShapePloter.RenderEntity(db, ExtBB.ConvertPL());

            //RendeDetail(ref db, RefPtDetail, out ExtDetail);
            RendeDetailNew(ref db, RefPtDetail, out ExtDetail, dt1, dt2, OverAllScale);

            LayoutTools.CreateLayout4Div(db, "图纸", ExtAA, ExtBB, ExtPlan, ExtDetail,
               Extensions.leftWidth, 5, Extensions.bottomHeight, 10, OverAllScale);
        }
       
        // 绘制立面图
        public void PlotElevationA(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitle(db,insertPoint, ref ext, "SECTION A-A", string.Format("(1:{0:G})", scale),  scale);
            Line2d AxisY = new Line2d(insertPoint, insertPoint.C2D(0, 1));
            
            Polyline M1 = new Polyline() { Closed = false };
            Point2d p0 = insertPoint.C2D(-0.5 * Width - 500, -Height - 500);
            Point2d p1 = p0.C2D(500);
            Point2d p2 = p1.C2D(0, Height);
            Point2d p22 = p2.Mirror(AxisY);
            Point2d p12 = p1.Mirror(AxisY);
            Point2d p02 = p0.Mirror(AxisY);


            M1.AddVertexAt(0, p0, 0, 0, 0);
            M1.AddVertexAt(1, p1, 0, 0, 0);
            M1.AddVertexAt(2, p2, 0, 0, 0);
            M1.AddVertexAt(3, p22, 0, 0, 0);
            M1.AddVertexAt(4, p12, 0, 0, 0);
            M1.AddVertexAt(5, p02, 0, 0, 0);

            Tools.RenderEntity(db, M1, ref ext, "H细线");
            //ext = ext.Add(((Extents3d)M1.Bounds).C2D());
            #region h标注
            DimPloter.DimRotated(db, ref ext, p22.C3D(), p12.C3D(), p22.C3D(5 * scale), 90, scale,Unit.Millimeter, Unit.Millimeter, "h");
            #endregion

            #region 剖断线
            RebarPLPloter.CreateBreakLine(db, ref ext, p0, p0.C2D(0, -500));
            RebarPLPloter.CreateBreakLine(db, ref ext, p02, p02.C2D(0, -500));
            RebarPLPloter.CreateBreakLine(db, ref ext, p0.C2D(0, -500), p02.C2D(0, -500));
            #endregion

            #region 钢筋网格
            GeneralRebar curRebar = (GeneralRebar)rebarList[0].Item1;

            List<Point3d> refRebar;
            RebarPLPloter.CreateGirdElev(db, ref ext, p2.C2D(0.5 * Width, -CoverThk - 0.5 * out_dia),
                curRebar.LineSegmentList[1], 10, ArrAlongW, plinthParameter.NetNumber+1, -plinthParameter.NetSapce, out refRebar);
            #endregion

            #region  箭头引线
            double width = 0,height= plinthParameter.NetSapce * plinthParameter.NetNumber;
            width = ArrAlongW.Sum();
            List<double> lList = new List<double>(); 
            for(int i=0;i< plinthParameter.NetNumber;i++)
            {
                lList.Add(plinthParameter.NetSapce);
            }
            List<double> wList=new List<double>();
            for(int i=1;i< ArrAlongW.Count;i++)
            {
                  wList.Add(ArrAlongW[i]);
            }
            //3
            RebarPLPloter.CreateLineArrowDB(db, ref ext, p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia).C3D(-width / 3, -100), ArrowDirection.North, lList, wList, dicNo[3].ToString(), scale);
            wList = new List<double>();

            Point3d p00 = p2.C2D(0.5 * Width, -CoverThk - 0.5 * out_dia).C3D(curRebar.LineSegmentList[1] / 2, 0).C3D(0, 0);
            //1
            RebarPLPloter.CreateLineArrowDB(db, ref ext, p00.C3D(0, -height - 50), ArrowDirection.West, lList, wList, dicNo[1].ToString(), scale);
            #endregion

            refRebar.Add(p2.C3D());
            refRebar.Add(p22.C3D());
            refRebar.Sort((x, y) => x.X.CompareTo(y.X));

            #region 上部和左侧标注
            //上部标注
            DimPloter.AddDoubleListDimRotated(db, ref ext, p2.C3D(0, 5 * scale), refRebar, scale,0, plinthParameter.sapceW);

            //左侧标注
            List<Point3d> refLength0=new List<Point3d>();
            refLength0.Add(p2.C3D());
            refLength0.Add(p00);   
            List<Point3d> refLength = new List<Point3d>();
            refLength.Add(p00);      
            refLength.Add(p00.C3D(0, -height));

            DimPloter.AddListDimRotated(db, ref ext, refLength0[0].C3D(-5 * scale - CoverThk),
         refLength0, 20, 90);
            DimPloter.AddListDimRotated(db, ref ext, refLength0[0].C3D(-5 * scale - CoverThk),
                 refLength, 20, 90, plinthParameter.NetSapce);
            #endregion

            #region 标记B 
            RebarPLPloter.AddBJByDirectiong(db, ref ext, p0.C3D(500, 480), ArrowDirection.North, "B", scale);
            RebarPLPloter.AddBJByDirectiong(db, ref ext, p0.C3D(500, -570), ArrowDirection.South, "B", scale);
            #endregion

            #region  多引线圆标记
            List<Point3d> N1List = new List<Point3d>();
            for(int i=2;i< refRebar.Count-2;i++)
            {
                if(i<4||i> refRebar.Count - 5)
                    N1List.Add(refRebar[i]);
            }
            RebarPLPloter.CreateMultiLineCicle(db, ref ext, p0.C3D(500+Width/2, 150), N1List, dicNo[2].ToString(), scale);

            List<Point3d> N2List = new List<Point3d>();
            for (int i = 3; i < refRebar.Count-1; i++)
            {
                if (i < 5||i> refRebar.Count - 4)
                    N2List.Add(refRebar[i].C3D(0,-100));
            }
            RebarPLPloter.CreateMultiLineCicle(db, ref ext, p0.C3D(500 + Width / 2,-height -20), N2List, dicNo[3].ToString(), scale);
            #endregion

            #region  1号钢筋长度
            GeneralRebar N1 = (GeneralRebar)rebarList[0].Item1;
            double L = N1.LineSegmentList[0] - Height - height;
            Point2d pinsert = p2.C2D(0.5 * Width, -CoverThk - 0.5 * out_dia);
            PLPloter.AddLine(db, pinsert.C2D(-curRebar.LineSegmentList[1] / 2, 0), pinsert.C2D(-curRebar.LineSegmentList[1] / 2, -height-5*scale), ref ext,"H细线");
            PLPloter.AddLine(db, pinsert.C2D(curRebar.LineSegmentList[1] / 2, 0), pinsert.C2D(curRebar.LineSegmentList[1] / 2, -height - 5 * scale) ,ref ext, "H细线");
            #endregion
        }


        // 绘制立面图
        public void PlotElevationB(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitle(db,insertPoint, ref ext, "SECTION B-B", string.Format("(1:{0:G})", scale), scale);
            Line2d AxisY = new Line2d(insertPoint, insertPoint.C2D(0, 1));

            Polyline M1 = new Polyline() { Closed = false};
            Point2d p0 = insertPoint.C2D(-0.5 * Length - 500,  - 500);
            Point2d p1 = p0.C2D(500);
            Point2d p2 = p1.C2D(0, Height);
            Point2d p22 = p2.Mirror(AxisY);
            Point2d p12 = p1.Mirror(AxisY);
            Point2d p02 = p0.Mirror(AxisY);


            M1.AddVertexAt(0, p0, 0, 0, 0);
            M1.AddVertexAt(1, p1, 0, 0, 0);
            M1.AddVertexAt(2, p2, 0, 0, 0);
            M1.AddVertexAt(3, p22, 0, 0, 0);
            M1.AddVertexAt(4, p12, 0, 0, 0);
            M1.AddVertexAt(5, p02, 0, 0, 0);

            Tools.RenderEntity(db, M1, ref ext, "H细线");
            //ext = ext.Add(((Extents3d)M1.Bounds).C2D());
            #region h标注
            DimPloter.DimRotated(db, ref ext, p22.C3D(), p12.C3D(), p22.C3D(5 * scale), 90, scale,Unit.Millimeter, Unit.Millimeter, "h");
            #endregion

            #region 剖断线
            RebarPLPloter.CreateBreakLine(db, ref ext, p0, p0.C2D(0, -500));
            RebarPLPloter.CreateBreakLine(db, ref ext, p02, p02.C2D(0, -500));
            RebarPLPloter.CreateBreakLine(db, ref ext, p0.C2D(0, -500), p02.C2D(0, -500));
            #endregion

            #region 钢筋网格
            GeneralRebar curRebar = (GeneralRebar)rebarList[1].Item1;
            List<Point3d> refRebar;
            RebarPLPloter.CreateGirdElev(db, ref ext, p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia),
                curRebar.LineSegmentList[1], 10, ArrAlongL, plinthParameter.NetNumber + 1, -plinthParameter.NetSapce, out refRebar);
            #endregion

            #region 箭头引线
            double height = plinthParameter.NetSapce * plinthParameter.NetNumber;
            double width = 0;
            width = ArrAlongL.Sum();
            RebarPLPloter.CreateLineArrowDB(db, ref ext, p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia).C3D(-width/2, -height+100-2.5*scale), ArrowDirection.West,  ArrAlongW, ArrAlongL, dicNo[1].ToString(), scale);

            List<double> lList = new List<double>();
            for (int i = 0; i < plinthParameter.NetNumber; i++)
            {
                lList.Add(plinthParameter.NetSapce);
            }
            List<double> wList = new List<double>();
            for (int i = 1; i < ArrAlongL.Count; i++)
            {
                  wList.Add(ArrAlongL[i]);
            }
            RebarPLPloter.CreateLineArrowDB(db, ref ext, p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia).C3D(-curRebar.LineSegmentList[1] / 3 , -100), ArrowDirection.North, lList, wList, dicNo[4].ToString(), scale);

            wList = new List<double>();

            Point3d p01 = p2.C3D(0.5 * Length, -CoverThk - 0.5 * out_dia);
            Point3d p00 = p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia).C3D(-curRebar.LineSegmentList[1] / 2 , 0).C3D(0, 0);

            RebarPLPloter.CreateLineArrowDB(db, ref ext, p01.C3D(curRebar.LineSegmentList[1]/2, -height-50), ArrowDirection.West, ArrAlongW, wList, dicNo[2].ToString(), scale);
            #endregion

            List<Point3d> linePts = refRebar;

            refRebar.Add(p2.C3D());
            refRebar.Add(p22.C3D());
            refRebar.Sort((x, y) => x.X.CompareTo(y.X));

            #region 标注
            //上部标注
            DimPloter.AddDoubleListDimRotated(db, ref ext, p2.C3D(0, 5 * scale), refRebar, scale);



            //左侧标注
            //Point3d p00 = p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia).C3D(-curRebar.LineSegmentList[1] / 2 + width / 2, 0).C3D(0, 0);
            List<Point3d> refLength0 = new List<Point3d>();
            refLength0.Add(p2.C3D());
            refLength0.Add(p00);
            List<Point3d> refLength = new List<Point3d>();
            refLength.Add(p00);
            refLength.Add(p00.C3D(0, -height));

            DimPloter.AddListDimRotated(db, ref ext, refLength0[0].C3D(-5 * scale - CoverThk),
         refLength0, 20, 90);
            DimPloter.AddListDimRotated(db, ref ext, refLength0[0].C3D(-5 * scale - CoverThk),
                 refLength, 20, 90, 100);
            #endregion 标注

            #region  A标记
            RebarPLPloter.AddBJByDirectiong(db, ref ext, p0.C3D(500+ 0.5 * Length, 480), ArrowDirection.North, "A", scale);
            RebarPLPloter.AddBJByDirectiong(db, ref ext, p0.C3D(500 + 0.5 * Length, -610), ArrowDirection.South, "A", scale);
            #endregion

            #region   多引线圆标记
            List<Point3d> N1List = new List<Point3d>();
            for (int i = 2; i < refRebar.Count - 2; i++)
            {
                if (i < 4||i> refRebar.Count - 5)
                    N1List.Add(refRebar[i].C3D(0,-100));
            }
            RebarPLPloter.CreateMultiLineCicle(db, ref ext, p0.C3D(500 + Width / 2, 150), N1List, dicNo[4].ToString(), scale);
            #endregion

            #region
            Point2d pinsert = p2.C2D(0.5 * Length, -CoverThk - 0.5 * out_dia);
            GeneralRebar N2 = (GeneralRebar)rebarList[1].Item1;

            #region  2号筋长
            double L2 = N2.LineSegmentList[0] - Height;
            PLPloter.AddLine(db, pinsert.C2D(-curRebar.LineSegmentList[1] / 2, 0), pinsert.C2D(-curRebar.LineSegmentList[1] / 2, -height-5 * scale), ref ext,"H细线");
            PLPloter.AddLine(db,pinsert.C2D(curRebar.LineSegmentList[1] / 2, 0), pinsert.C2D(curRebar.LineSegmentList[1] / 2, -height - 5 * scale), ref ext, "H细线");
            #endregion

            #region 1号筋长
            GeneralRebar N1 = (GeneralRebar)rebarList[0].Item1;
            double L = N1.LineSegmentList[0] - Height;
            linePts.RemoveAt(0);
            linePts.RemoveAt(linePts.Count-1);
            foreach (var p in linePts)
            {
               // p.C3D(0, -L);
                Point3d pEnd = new Point3d(p.X, pinsert.C3D(0, -height - 5 * scale).Y, 0);// p.C3D(0, -L);
                Point3d pSt = pEnd.C3D(0, height +5 * scale);// pEnd.C3D(0,L);
                PLPloter.AddLine(db,pSt.C2D(), pEnd.C2D(), ref ext,"H细线");
            }
            #endregion

            #endregion
        }
        public void RendeDetail(ref Database db, Point2d insertPoint, out Extents2d ext)
        {
            ext = new Extents2d(insertPoint, insertPoint);

            // N1
            GeneralRebar N1 = (GeneralRebar)rebarList[0].Item1;
            int NumOfN1 = rebarList[0].Item2;

            string LeftMark = string.Format("h+{0:G}", N1.LineSegmentList[0] - Height);
            string MidMark = string.Format("{0:G}", N1.LineSegmentList[1]);
            string RightMark = LeftMark;
            string RebarInfo = string.Format("{0:G} R{1:G}", NumOfN1, Convert.ToInt32(N1.Diameter));
            string RebarTotalLength = string.Format("2h+{0:F0}", N1.TotalLength - 2 * Height);

            RebarPLPloter.CreateRebarModel(db, ref ext, insertPoint, LeftMark, RightMark, MidMark, RebarInfo, RebarTotalLength,
                1, N1.LineSegmentList[0], N1.LineSegmentList[2], N1.LineSegmentList[1], 0, 20);

            // N2
            GeneralRebar N2 = (GeneralRebar)rebarList[1].Item1;
            int NumOfN2 = rebarList[1].Item2;

            LeftMark = string.Format("h+{0:G}", N2.LineSegmentList[0] - Height);
            MidMark = string.Format("{0:G}", N2.LineSegmentList[1]);
            RightMark = LeftMark;
            RebarInfo = string.Format("{0:G} R{1:G}", NumOfN2, Convert.ToInt32(N2.Diameter));
            RebarTotalLength = string.Format("2h+{0:F0}", N2.TotalLength - 2 * Height);

            RebarPLPloter.CreateRebarModel(db, ref ext, insertPoint.C2D(0.8*(Width+Length)), LeftMark, RightMark, MidMark, RebarInfo, RebarTotalLength,
                2, N2.LineSegmentList[0], N2.LineSegmentList[2], N2.LineSegmentList[1], 0, 20);




        }
        /// <summary>
        /// 绘制钢筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="insertPoint"></param>
        /// <param name="ext"></param>
        public void RendeDetailNew(ref Database db, Point2d insertPoint, out Extents2d ext,
            System.Data.DataTable dt1, System.Data.DataTable dt2, double scale = 50)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -2 * scale);

            //PolylinePloter.AddPloy4(db, ref ext, M1, 0.5 * 10, 0.5 * 10, 20);

            // 查询数据
            //string selectString = string.Format("SELECT * FROM span_tbl where Name='{0}'", SpName);
            //var consetr = string.Format("data source=cdb-2ashfo5g.bj.tencentcdb.com;port=10033;user id=wyz;password=wang1234;DataBase=nep2021;charset=utf8"); ;// string.Format("server={0};port={3};user id={1};password={2};charset=utf8;database={4}", address, user, password, port,database);
            //System.Data.DataTable dt = SRBMain.MySqlHelper.(consetr, selectString, System.Data.CommandType.Text);

            // 绘制表格
            List<string> list = new List<string>();
            list.Add("编号");
            list.Add("直径\\P(mm)");
            list.Add("大样");
            list.Add("单根长\\P(cm)");
            list.Add("根数");
            list.Add("总长\\P(m)");
            list.Add("单位重\\P(kg/m)");
            list.Add("总重\\P(kg)");
            //list.Add("小计(kg)");
            double height = 0;
            double width = 0;
            ModelTablePloter.DrawCapRebarTable(db, ref ext, M1.C3D(-0.5 * Width + CoverThk), dt1, list, dt1.Rows.Count + 1, list.Count, ref height, ref width, Extensions.curFont, scale, true, netNumber);
            double ActualWidth = 0, ActualHeight = 0;
            TextPloter.GetTextActualWidth(db, "垫石钢筋明细表", scale, out ActualWidth, out ActualHeight, 5);
            TextPloter.AddMText(db,M1.C3D(-0.5 * Width + CoverThk + (width - ActualWidth) / 2, ActualHeight + scale * 2), ref ext, "承台钢筋明细表", scale, 5, ActualWidth + 5, Extensions.curFont);

            List<string> list1 = new List<string>();
            list1.Add("名称及规格");
            list1.Add("名称及规格");
            list1.Add("单位");
            list1.Add("总重");
            list1.Add("合计");
            double height1 = 0;
            double width1 = 0;
            TextPloter.GetTextActualWidth(db, "垫石材料数量表(全桥" + plinthParameter.structureNumber + "个)", scale, out ActualWidth, out ActualHeight, 5);
            ModelTablePloter.DrawCapMaterialsTable(db, ref ext, M1.C3D(-0.5 * Width + CoverThk, -height - ActualHeight * 3), dt2, list1, dt2.Rows.Count + 1, list1.Count, ref height1, ref width1, Extensions.curFont, scale);
            //TextPloter.AddMText(db, M1.C3D(-0.5 * Width + CoverThk + (width1 - ActualWidth) / 2, -height - ActualHeight * 2 + scale * 2), ref ext, "垫石材料数量表(全桥" + plinthParameter.structureNumber + "个)", scale, 5,80, Extensions.curFont);
            TextPloter.AddMText(db,M1.C3D(-0.5 * Width + CoverThk + (width1 - ActualWidth) / 2, -height - ActualHeight * 2 + scale * 2), ref ext, "垫石材料数量表(全桥" + plinthParameter.structureNumber + "个)", scale, 5, ActualWidth + 2 * scale, Extensions.curFont);

            // 文字
            string text = "注";
            Point3d p1 = M1.C3D(-0.5 * Width + CoverThk + width1 + scale * 5, -height - ActualHeight * 3);
            TextPloter.AddMText(db, p1, ref ext, text, scale, 2.5,10, Extensions.curFont);

            text = @"1.本图尺寸除钢筋直径以毫米计外,
均会以厘米为单位。
2.图中所示保护层为净保护层厚度。
3.钢筋按尺寸9m长计算连接器数量。
4.施工承台时应注意预埋墩身钢筋。
5.本图适用于XX号墩";
            Point3d p2 = M1.C3D(-0.5 * Width + CoverThk + width1 + scale * 5, -height - ActualHeight * 4);
            //TextPloter.AddMText(db, p2, ref ext, text, scale, 2.5,44, Extensions.curFont);
            TextPloter.AddMText(db,p2, ref ext, text, scale, 2.5, 50 * scale, Extensions.curFont);

        }


        /// <summary>
        /// 绘制平面图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public void PlotPlan(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            Point2d CT = insertPoint;


            ext = new Extents2d(CT, CT);

            TextPloter.AddTitle(db, CT, ref ext, "PLAN", string.Format("(1:{0:G})", scale), scale);

            Point2d M1 = CT.C2D(0, -25 * scale);

            PLPloter.AddPloy4(db, M1, 0.5 * Width, 0.5 * Width, Length,ref ext,"H细线");

            #region 网格
            List<Point3d> leftPts, topPts;
            RebarPLPloter.CreateLineGrid(db, M1.C2D(-0.5 * Width + CoverThk + 1.5 * out_dia, -CoverThk - 1.5 * out_dia), ArrAlongL, ArrAlongW,
                ref ext, out_dia, out leftPts, out topPts);
            #endregion

            #region 箭头引线
            double width = 0;
            double height = 0;
            width = ArrAlongW.Sum();
            height = ArrAlongL.Sum();
            RebarPLPloter.CreateLineArrowDB(db, ref ext, topPts[0].C3D(0, -height/2), ArrowDirection.West, ArrAlongL, ArrAlongW, "2", scale);
            RebarPLPloter.CreateLineArrowDB(db, ref ext, leftPts[leftPts.Count-1].C3D(width/2, 0), ArrowDirection.South, ArrAlongL, ArrAlongW, "1", scale);
            #endregion

            #region 标注
            // 两层左侧标注
            DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
                new List<Point3d>() { M1.C3D(0, -Length), leftPts[0], leftPts[1] }, 20, 90);
            DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
                 new List<Point3d>() { leftPts[1], leftPts[leftPts.Count - 2] }, 20, 90, 100);
            DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk),
                new List<Point3d>() { leftPts[leftPts.Count - 2], leftPts[leftPts.Count - 1], M1.C3D() }, 20, 90);
            DimPloter.AddListDimRotated(db, ref ext, leftPts[0].C3D(-5 * scale - CoverThk - 5 * scale),
                new List<Point3d>() { M1.C3D(0, -Length), M1.C3D() }, 20, 90);
            
            // 上部标注
            //DimPloter.AddListDimRotated(db, ref ext, topPts[0].C3D(0, 5 * scale + CoverThk), topPts, 20);
            //DimPloter.AddListDimRotated(db, ref ext, topPts[0].C3D(0, 5 * scale + CoverThk + 5 * scale),
            //    new List<Point3d>() { M1.C3D(-Width * 0.5), M1.C3D(Width * 0.5) }, 20);
            //;
            topPts.Add(M1.C3D(-Width * 0.5).C3D());
            topPts.Add(M1.C3D(Width * 0.5).C3D());
            topPts.Sort((x, y) => x.X.CompareTo(y.X));
            DimPloter.AddDoubleListDimRotated(db, ref ext, topPts[0].C3D(0, 10 * scale + CoverThk), topPts, scale);
            #endregion
        }



        public override DBObjectCollection Render()
        {
            var f = new DBObjectCollection();



            return f;
        }
    }
}
